/*
 * @Author: zdc 3215400595@qq.com
 * @Date: 2023-07-20 18:30:31
 * @LastEditors: zdc 3215400595@qq.com
 * @LastEditTime: 2023-07-21 10:11:19
 * @FilePath: /Use_of_technology/Indefinite parameters/args.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// #define _GNU_SOURCE
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <iostream>
#define LOG(fmt, ...) printf("[%s:%d]" fmt, __FILE__, __LINE__, __VA_ARGS__);

void PrintNum(int count, ...)
{
    va_list ap;
    va_start(ap, count);
    for (int i = 0; i < count; i++)
    {
        int num = va_arg(ap, int);
        printf("param[%d]:%d\n", i, num);
    }
    va_end(ap);
}
void my_printf(const char *fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    char *res;
    int ret = vasprintf(&res, fmt, ap);
    if (ret != -1)
    {
        printf(res);
        free(res);
    }
    va_end(ap);
}
void my_cplus_printf()
{
    std::cout << std::endl;
}
template <class T, class... Args>
void my_cplus_printf(const T &val, Args &&...args)
{
    // 打印不同的使用递归的思想
    std::cout << val << " ";

    my_cplus_printf(std::forward<Args>(args)...);
}
int main()
{
    my_cplus_printf("tongtong");
    my_cplus_printf("tongtong", "超努力");
    my_cplus_printf("tongtong", "超努力", 999);
    return 0;
}
// int main()
// {
//     my_printf("%s-%d\n", "tongtong", 777);

//     // PrintNum(2, 666, 777);
//     // PrintNum(5, 1, 2, 3, 4, 5);
//     return 0;
// }